﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using XiaoYuJi.Core.Jwt;
using XiaoYuJi.Entity.SysEntitys;
using XiaoYuJi.Service.IServices;
using XiaoYuJi.Service.SysServices;

namespace XiaoYuJi.API.Controllers.SystemControllers;
/// <summary>
/// 系统授权验证API接口
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class AuthController : ControllerBase
{
    private readonly IAuthService _authService;
    private readonly IMenuService _menuService;

    public AuthController(IAuthService authService,IMenuService menuService)
    {
        this._authService = authService;
        this._menuService = menuService;
    }


    /// <summary>
    /// 小鱼记后台管理系统登录
    /// </summary>
    /// <param name="userName">用户名</param>
    /// <param name="password">密码</param>
    /// <returns></returns>
    [HttpPost("AdminLogin")]    //api/auth/AdminLogin   API调用链接
    public async Task<IActionResult> AdminLogin(string userName,string password)
    {
        return Ok(await _authService.AdminLogin(userName, password));
    }

    [HttpGet,Route("GetSystemMenu")]
    [Authorize]
    public async Task<IActionResult> GetSystemMenu()
    {
        TokenPayload payload = JwtHelper.GetTokenPayload(HttpContext);

        var apiResult = await _menuService.GetSystemMenu(payload.Id);

        return Ok(apiResult);
    }

}
